package org.eclipse.mylyn.rememberthemilk.core;

import static org.junit.Assert.*;

import java.util.Map;

import org.eclipse.mylyn.rememberthemilk.core.RTMAttributeMapper;
import org.eclipse.mylyn.rememberthemilk.core.RTMCorePlugin;
import org.eclipse.mylyn.rememberthemilk.core.RTMAttributeMapper.Attribute;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.ITask.PriorityLevel;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.mdt.rtm.data.RtmData;
import com.mdt.rtm.data.RtmTask;
import com.mdt.rtm.data.RtmTask.Priority;

public class RTMAttributeMapperTests extends BaseRtmTests {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testMapToRepositoryKey() {
		TaskRepository repository = createTaskRepository();
		RTMAttributeMapper mapper = new RTMAttributeMapper(repository);
		
		
		String mappedKey = mapper.mapToRepositoryKey(null, TaskAttribute.SUMMARY);
		
		assertEquals("incorrect mappedKey returned", "name", mappedKey);
	}
	
	@Test
	public void testGetOptionsForPriority() {
		// set up the fixture
		TaskRepository repository = createTaskRepository();
		RTMAttributeMapper mapper = new RTMAttributeMapper(repository);
		TaskData data = new TaskData(mapper, repository.getRepositoryLabel(), repository.getRepositoryUrl(), "1");
		TaskAttribute attribute = data.getRoot().createAttribute(Attribute.PRIORITY.getRTMKey());
		
		// Exercise SUT
		Map<String, String> optionsMap = mapper.getOptions(attribute);

		// Verify outcome
		assertEquals(Priority.High.toString(), optionsMap.get(PriorityLevel.P1.toString()));
		assertEquals(Priority.Low.toString(), optionsMap.get(PriorityLevel.P4.toString()));
		assertEquals(Priority.Medium.toString(), optionsMap.get(PriorityLevel.P2.toString()));
		assertEquals(Priority.None.toString(), optionsMap.get(PriorityLevel.P3.toString()));
	}
	
	@Test
	public void testGetOptionsForStatus() {
		// set up
		TaskRepository repository = createTaskRepository();
		RTMAttributeMapper mapper = new RTMAttributeMapper(repository);
		TaskData data = new TaskData(mapper, repository.getRepositoryLabel(), repository.getRepositoryUrl(), "1");
		TaskAttribute attribute = data.getRoot().createAttribute(Attribute.STATUS.getRTMKey());
		
		// Exercise
		Map<String, String> optionsMap = mapper.getOptions(attribute);
		
		// verify
		assertEquals("Complete", optionsMap.get("complete"));
		assertEquals("Incomplete", optionsMap.get("incomplete"));
	}

	@Test
	public void testGetProvidedOptions() {
		// set up
		TaskRepository repository = createTaskRepository();
		RTMAttributeMapper mapper = new RTMAttributeMapper(repository);
		TaskData data = new TaskData(mapper, repository.getRepositoryLabel(), repository.getRepositoryUrl(), "1");
		TaskAttribute attribute = data.getRoot().createAttribute("provided");
		attribute.putOption("key", "value");
		
		// Exercise
		Map<String, String> optionsMap = mapper.getOptions(attribute);
		assertEquals("value", optionsMap.get("key"));
	}
}
